package com.jh.mapper;

import com.jh.annotation.AutoFill;
import com.jh.dto.EmployeePageQueryDTO;
import com.jh.dto.PasswordEditDTO;
import com.jh.entity.Employee;
import com.jh.enumeration.OperationType;
import com.jh.vo.EmployeeVO;
import org.apache.ibatis.annotations.*;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
    /**
     * 根据用户名查询员工
     * @param phone
     * @return
     */
    @Select("select * from jh_clothing.employee where phone = #{phone}")
    Employee getByUsername(String phone);

    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */


    Page<EmployeeVO> page(Page<EmployeeVO> page, @Param("employeePageQueryDTO") EmployeePageQueryDTO employeePageQueryDTO);


    /**
     * 员工修改
     * @param employee
     */
    @AutoFill(value= OperationType.UPDATE)
    void update(Employee employee);


    /**
     * 员工删除
     * @param id
     */
    @Update("update jh_clothing.employee set status=0 where id=#{id}")
    void delete(Long id);

    /**
     * 根据身份证号查询员工
     * @param idCard
     * @return
     */
    @Select("select * from jh_clothing.employee where id_card=#{idCard}")
    Employee findByIdCard(String idCard);

    /**
     * 新增员工
     * @param employee
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into jh_clothing.employee(name, password, phone, sex, position, address, birth_date, id_card, status, create_time, update_time, create_user, update_user)" +
            " values(#{name},#{password},#{phone},#{sex},#{position},#{address},#{birthDate},#{idCard},#{status},#{createTime},#{updateTime},#{createUser},#{createUser}) ")
    void add(Employee employee);

    /**
     * 根据员工id查询密码
     * @param passwordEditDTO
     */
    @AutoFill(value = OperationType.GETBYEMPID)
    @Select("SELECT password from jh_clothing.employee where id=#{empId}")
    String getbyEmpId(PasswordEditDTO passwordEditDTO);


    /**
     * 修改密码
     * @param passwordEditDTO
     */
    @Update("UPDATE jh_clothing.employee set password=#{newPassword} where id=#{empId}")
    void updatePassword(PasswordEditDTO passwordEditDTO);
}
